---
category: Random
created: '2020-05-05'
title: Generate a random floating point number in given range
updated: '2021-10-13'
---

**JavaScript version**

```js randomFloat.js
const randomFloat = (min, max) => Math.random() * (max - min) + min;
```

**TypeScript version**

```ts randomFloat.ts
const randomFloat = (min: number, max: number): number => Math.random() * (max - min) + min;
```

## See also

-   [Generate a random integer in given range](https://phuoc.ng/collection/1-loc/generate-a-random-integer-in-given-range/)
-   [Generate a weighted random number in given range](https://phuoc.ng/collection/1-loc/generate-a-weighted-random-number-in-given-range/)
